package com.qfjy.config.example5;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName BlogTopicConfig
 * @Description TODO
 * @Author guoweixin
 * @Date 2022/11/22
 * @Version 1.0
 */
@Configuration
public class BlogTopicConfig {

    /**
     * 1、定义交换机 （主题交换机）
     * 2、定义队列（ JAVA  Python， ALL队列)
     * 3、交换机和队列依次进行绑定
     */

    @Bean
    public TopicExchange blogTopicExchange(){
        return new TopicExchange("blogTopicExchange");
    }
    /**
     * 定义队列
     */
    @Bean
    public Queue blogJavaQueue(){
        return new Queue("blog.java.queue");
    }

    @Bean
    public Queue blogPythonQueue(){
        return new Queue("blog.python.queue");
    }

    @Bean
    public Queue blogAllQueue(){
        return new Queue("blog.all.queue");
    }

    /**
     * 交换机和队列依次进行绑定
     */
    @Bean
    public Binding bindTopicExchangeJavaQueue(Queue blogJavaQueue,TopicExchange blogTopicExchange){
        return BindingBuilder.bind(blogJavaQueue).to(blogTopicExchange).with("blog.java");
    }
    @Bean
    public Binding bindTopicExchangePythonQueue(Queue blogPythonQueue,TopicExchange blogTopicExchange){
        return BindingBuilder.bind(blogPythonQueue).to(blogTopicExchange).with("blog.python");
    }
    @Bean
    public Binding bindTopicExchangeAllQueue(Queue blogAllQueue,TopicExchange blogTopicExchange){
        return BindingBuilder.bind(blogAllQueue).to(blogTopicExchange).with("blog.#");
    }
}
